# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=faad2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.7
pkgrel=2
pkgdesc="ISO AAC audio decoder (mingw-w64)"
arch=('any')
url="http://www.audiocoding.com/"
license=('GPL')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("yasm" "${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=(https://downloads.sourceforge.net/sourceforge/faac/${_realname}-${pkgver}.tar.bz2
        0001-update-ac.mingw.patch
        0002-no-undefined.mingw.patch
        0003-frontend.mingw.patch
        faad2-2.7-libmp4ff-install-mp4ff_int_types_h.patch
        faad2-2.7-libmp4ff-shared-lib.patch
        faad2-2.7-man1_MANS.patch)
sha256sums=('14561b5d6bc457e825bfd3921ae50a6648f377a9396eaf16d4b057b39a3f63b5'
            'b571eb7b6242bfb90d17495293a66d43ba6c52c11f5c3fdca983021da752bb6a'
            'fc7617ca8e4d8415aa94f94f630b75d41d070d8f8117b81710d6149c87b5b5f2'
            'f164030924f920649f9ac0dd89c2d668bb9d4f86b0b0c0e9710ee753555e76ca'
            'c554313121f935aaabbe5b05addfc065bdf782bc0634ee9a91ceabde001ea823'
            'd70e8e2a4afe4eb7b999410af58d303feb9b459a7803e6c00212eeb8ac4b6ac9'
            'e3e745cca309443d0149a09cc9988fec09c51e242b0e564afcb0af787dbb9031')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/faad2-2.7-libmp4ff-shared-lib.patch"
  patch -p0 -i "${srcdir}/faad2-2.7-libmp4ff-install-mp4ff_int_types_h.patch"
  patch -p1 -i "${srcdir}/faad2-2.7-man1_MANS.patch"
  patch -p1 -i "${srcdir}/0001-update-ac.mingw.patch"
  patch -p1 -i "${srcdir}/0002-no-undefined.mingw.patch"
  patch -p1 -i "${srcdir}/0003-frontend.mingw.patch"

  WANT_AUTOMAKE=latest autoreconf --force --install
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
